package lamdba;

import org.junit.Test;


import java.util.*;
import java.util.stream.Stream;
/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : FunctionTest
 * @Author : 54061
 * @Date: 2022/2/28 13:55
 */
public class FunctionTest {

    @Test
    public void testConsumer(){
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        list.forEach(i->System.out.println(i));
        System.out.println("++++++++++++++++++++++++++++++++++");
        Map<Integer, String> map = new HashMap<>();
        map.put(1001, "张三1");
        map.put(1002, "张三2");
        map.put(1003, "张三3");
        map.put(1004, "张三4");
        map.forEach((k,v)-> System.out.println(k+":"+v));
    }

    @Test
    public void testSupplier(){
        Stream.generate(()->Math.random()).forEach(s-> System.out.println(s));
    }

    @Test
    //UnsupportedOperationException
    public void testPredicate(){
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        list.removeIf(i->i>3);
        list.forEach(i-> System.out.println(i));

    }

    @Test
    public void testFunction(){
        HashMap<Integer,Employee> map = new HashMap<>();
        Employee e1 = new Employee(1, "张三", 8000);
        Employee e2 = new Employee(2, "李四", 9000);
        Employee e3 = new Employee(3, "王五", 10000);
        Employee e4 = new Employee(4, "赵六", 11000);
        Employee e5 = new Employee(5, "钱七", 12000);

        map.put(e1.getId(), e1);
        map.put(e2.getId(), e2);
        map.put(e3.getId(), e3);
        map.put(e4.getId(), e4);
        map.put(e5.getId(), e5);
        map.forEach((k,v)-> System.out.println(k+":"+v));
        System.out.println("+++++++++++++++++++++++++++++++++++");
        map.replaceAll((k,v)->{
            if(v.getSalary() < 10000){
                v.setSalary(10000);
            }
            return v;
        });
        map.forEach((k,v)-> System.out.println(k+":"+v));
    }

}
